package com.squirrel.michale;

/**
 * @author guanhao 观浩
 * @version 1.0.0.0
 * @createTime 2023/3/28 7:26 AM
 * @company Michale Squirrel
 * @link
 * @description
 */
public class LeetCode1419 {

    public int minNumberOfFrogs(String croakOfFrogs) {

        int cCount = 0;
        int rCount = 0;
        int oCount = 0;
        int aCount = 0;
        int kCount = 0;

        int flog = 0;
        int result = 0;

        for (char craw : croakOfFrogs.toCharArray()) {
            if (craw == 'c') {
                cCount++;
                flog++;
            } else if (craw == 'r') {
                rCount++;
            }else if (craw == 'o') {
                oCount++;
            }else if (craw == 'a') {
                aCount++;
            }else if (craw == 'k') {
                kCount++;
                --flog;
            }
            result = Math.max(result, flog);
            if (cCount >= rCount && rCount >= oCount && oCount >= aCount && aCount >= kCount) {
                continue;
            }else{
                return -1;
            }
        }

        if (cCount != rCount || rCount != oCount || oCount != aCount || aCount != kCount) {
            return -1;
        }

        return result;

    }
}
